import time

from selenium import webdriver
from selenium.webdriver import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.firefox.service import Service
import unittest
from selenium.webdriver.support.select import Select


class MyTestCase(unittest.TestCase):
    driver = None

    @classmethod
    def setUpClass(cls) -> None:
        service = Service(executable_path="../driver/geckodriver.exe")
        cls.driver = webdriver.Firefox(service=service)

    def test_alert(self):
        """测试 网页中句柄的问题"""

        self.driver.get("https://www.jd.com")


        self.driver.add_cookie({'name': 'hanamaki', 'value': 'andy'})
        list_dict = self.driver.get_cookies()
        print(list_dict)
        # cookies 是 以  字典的形式 去 存放的
        # 添加 删除
        for cookie in list_dict:
            print("%s  -> %s" % (cookie['name'], cookie['value']))



    @classmethod
    def tearDownClass(cls) -> None:
        cls.driver.close()  # 只会 关闭一个 标签页
        # cls.driver.quit()  # 推出浏览器  全部关闭所有的标签页

        pass


if __name__ == '__main__':
    unittest.main()
